package com.kuang.controller;

import io.undertow.server.handlers.form.MultiPartParserDefinition;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartException;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class BaseController {


    @ResponseBody
    @ExceptionHandler(value = MultipartException.class)
    public Object fileUploadExceptionHandler(MultipartException exception){
        Map<String,Object> map = new HashMap<>();
        map.put("code",999);
        Throwable rootCause = exception.getRootCause();
        if(rootCause instanceof MultiPartParserDefinition.FileTooLargeException){
            map.put("msg","文件太大");
        }
        return map;
    }
}
